import useSWR from 'swr';
import { useEffect } from 'react';
import { getTracker } from '../sdk/tracker';
import { getUserInfo } from '@/api/system';
import { useAuthStore } from '@/store/useAuthStore';
export const usePageView = (
	eventName: string,
	params?: Record<string, string>
) => {
	const token = useAuthStore(s => s.token);
	const { data } = useSWR(token ? 'getPermission' : null, getUserInfo);

	useEffect(() => {
		if (data) {
			const send = async () => {
				const tracker = await getTracker();
				tracker?.send({
					projectName: 'dashboard-mobile',
					userId: data.user.userId,
					userName: data.user.nickName,
					eventName,
					...params
				});
			};
			send();
		}
	}, [data]);
};

